using System;
using System.Collections.Generic;
using System.Web.Http;
using Medora.Model.Institutions;
using Medora.Model.Persons;
using Medora.Services;

namespace Medora.Web.App_Code
{
    public class SectorsController : ControllerBase<Sector, SectorFilter>
    {
        public SectorsController(ISectorsService service)
            : base(service)
        {
        }

        [ActionName("GetByDepartment")]
        public IEnumerable<Sector> GetByDepartment(Guid departmentId)
        {
            var user = System.Web.Security.Membership.GetUser(User.Identity.Name);
            if (user != null && user.ProviderUserKey != null)
            {
                return _service.Get(new SectorFilter { DepartmentId = departmentId });
            }
            return null;
        }

        [ActionName("GetByInstitution")]
        public IEnumerable<Sector> GetByInstitution(Guid institutionId)
        {
            var user = System.Web.Security.Membership.GetUser(User.Identity.Name);
            if (user != null && user.ProviderUserKey != null)
            {
                return _service.Get(new SectorFilter { InstitutionId = institutionId });
            }
            return null;
        }

        [ActionName("GetByCurrentInstitution")]
        public IEnumerable<Sector> GetByCurrentInstitution()
        {
            var user = System.Web.Security.Membership.GetUser(User.Identity.Name);
            if (user != null && user.ProviderUserKey != null)
            {
                var userId = (Guid)user.ProviderUserKey;
                return (_service as ISectorsService).GetByInstitutionByUserId(userId);
            }
            return null;
        }
    }
}